package com.ruoyi.web.controller.product;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MedicineRegister;
import com.ruoyi.system.service.IMedicineRegisterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中药登记Controller
 * 
 * @author ruoyi
 * @date 2025-01-23
 */
@RestController
@RequestMapping("/system/register")
public class MedicineRegisterController extends BaseController
{
    @Autowired
    private IMedicineRegisterService medicineRegisterService;

    @GetMapping("/getInfoByRegisterNum")
    @Anonymous
    public TableDataInfo getInfoByRegisterNum(MedicineRegister medicineRegister)
    {
        startPage();
        List<MedicineRegister> list = medicineRegisterService.selectMedicineRegisterList(medicineRegister);
        return getDataTable(list);
    }

    /**
     * 查询中药登记列表
     */
    @PreAuthorize("@ss.hasPermi('system:register:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineRegister medicineRegister)
    {
        startPage();
        List<MedicineRegister> list = medicineRegisterService.selectMedicineRegisterList(medicineRegister);
        return getDataTable(list);
    }

    /**
     * 导出中药登记列表
     */
    @PreAuthorize("@ss.hasPermi('system:register:export')")
    @Log(title = "中药登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineRegister medicineRegister)
    {
        List<MedicineRegister> list = medicineRegisterService.selectMedicineRegisterList(medicineRegister);
        ExcelUtil<MedicineRegister> util = new ExcelUtil<MedicineRegister>(MedicineRegister.class);
        util.exportExcel(response, list, "中药登记数据");
    }

    /**
     * 获取中药登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:register:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medicineRegisterService.selectMedicineRegisterById(id));
    }

    /**
     * 新增中药登记
     */
    @PreAuthorize("@ss.hasPermi('system:register:add')")
    @Log(title = "中药登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineRegister medicineRegister)
    {
        return toAjax(medicineRegisterService.insertMedicineRegister(medicineRegister));
    }

    /**
     * 修改中药登记
     */
    @PreAuthorize("@ss.hasPermi('system:register:edit')")
    @Log(title = "中药登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineRegister medicineRegister)
    {
        return toAjax(medicineRegisterService.updateMedicineRegister(medicineRegister));
    }

    /**
     * 删除中药登记
     */
    @PreAuthorize("@ss.hasPermi('system:register:remove')")
    @Log(title = "中药登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicineRegisterService.deleteMedicineRegisterByIds(ids));
    }
}
